<?php
include 'test_header.php';
class test_db_obj_code extends UnitTestCase{	

	function setUp(){
		$db = db_connect();

		$sql = "
CREATE TABLE IF NOT EXISTS `code` (
  `code_file_name` varchar(64) NOT NULL,
  `problem_no` int(11) NOT NULL,
  `username` varchar(256) NOT NULL,
  `language` varchar(16) NOT NULL,
  `modify_time` datetime NOT NULL,
  `create_time` datetime NOT NULL,
  `time_limit` varchar(32) not null,
  `mem_limit`  varchar(32) not null ,
  `content` text NOT NULL,
  KEY `username` (`username`(255))
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
" ;
		
		$res = $db->query( $sql );
	}
	
	function tearDown(){

		$db = db_connect();

		$sql = "drop table code";

		$res = $db->query( $sql );
	}

	function test_just_save_user_code(){

		$db = db_connect();

		$db_obj_code = new db_obj_code( $db ) ;
		
		$db_obj_code->set( 'code_file_name' , 'judas_1000_'.time() );
		$db_obj_code->set( 'problem_no' , '1000' );
		$db_obj_code->set( 'username' , 'judas' );
		$db_obj_code->set( 'language' , 'ANSI C'); 
		$db_obj_code->set( 'create_time' ,  date("Y-m-d H:i:s",time()+8*60*60) );
		$db_obj_code->set( 'modify_time' ,  date("Y-m-d H:i:s",time()+8*60*60) );
		$db_obj_code->set( 'mem_limit' , '1000' ) ;
		$db_obj_code->set( 'time_limit' , '123' ) ;
		
		$db_obj_code->set( 'content' , 'test' );
		$this->assertTrue( $db_obj_code->save() );

	}

}


$test = new test_db_obj_code();
$test->run( new HtmlReporter() );



